<?php

if(!empty($_POST)){

   $username = $_POST['username'];
   $password = $_POST['password'];


   if(!empty($_COOKIE['password'])&& $_POST['password']==$_COOKIE['password']){$password = $_COOKIE['password'];}

$link = mysqli_connect('127.0.0.1','root','root','cms');
if(!$link){
	die('数据库连接失败');
}

mysqli_query($link,'set names utf8');



$sql = "select * from `admin` where `username`='$username' and `password`='$password'";

$result = mysqli_query($link,$sql);



$data = mysqli_fetch_assoc($result);

if(!empty($data)){
	//echo '<script> alert("登陆成功");location.href="index.php";</script>';die;

	session_start();
	$_SESSION['admin']=$data;

    if(!empty($_POST['check'])){
    	setcookie('username',$data['username'],time()+3600*24);
    	setcookie('password',$data['password'],time()+3600*24);
    }
    else{

    	setcookie('username','',0);
    	setcookie('password','',0);
    }


	header('location:index.php');



}
 else{
 	echo '<script> alert("登录失败");history.go(-1);</script>';die;
 }


}

?>
<!DOCTYPE HTML>
<html>
<head>
<title>Login</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="Shoppy Responsive web template, Bootstrap Web Templates, Flat Web Templates, Android Compatible web template,
Smartphone Compatible web template, free webdesigns for Nokia, Samsung, LG, SonyEricsson, Motorola web design" />
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="all">
<!-- Custom Theme files -->
<link href="css/style.css" rel="stylesheet" type="text/css" media="all"/>
<!--js-->
<script src="js/jquery-2.1.1.min.js"></script>
<!--icons-css-->
<link href="css/font-awesome.css" rel="stylesheet">
<!--Google Fonts-->
<link href='https://fonts.googleapis.com/css?family=Carrois+Gothic' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Work+Sans:400,500,600' rel='stylesheet' type='text/css'>
<!--static chart-->
</head>
<body>
<div class="login-page">
    <div class="login-main">
    	 <div class="login-head">
				<h1>登 录</h1>
			</div>
			<div class="login-block">
				<form action="" method="post">
					<input type="text" name="username" value="<?php echo !empty($_COOKIE['username'])?$_COOKIE['username']:'';?>" placeholder="请输入邮箱"  >
					<input type="password" name="password" class="lock" value="<?php echo !empty($_COOKIE['password'])?$_COOKIE['password']:''; ?>" placeholder="请输入密码" >
					<div class="forgot-top-grids">
						<div class="forgot-grid">
							<ul>
								<li>
									<input type="checkbox" name="check"  id="brand1" <?php echo !empty($_COOKIE['username'])?'checked':'';?> value="1">
									<label for="brand1"><span></span>记住我（公用电脑请勿选择该项）</label>
								</li>
							</ul>
						</div>
						<div class="forgot">
							<a href="#">忘记密码？</a>
						</div>
						<div class="clearfix"> </div>
					</div>
					<input type="submit" name="Sign In" value="登 录">
					<h3>未注册？<a href="signup.html"> 立即注册</a></h3>
					<h2>或用以下方式登录</h2>
					<div class="login-icons">
						<ul>
							<li><a href="#" class="facebook"><i class="fa fa-facebook"></i></a></li>
							<li><a href="#" class="twitter"><i class="fa fa-twitter"></i></a></li>
							<li><a href="#" class="google"><i class="fa fa-google-plus"></i></a></li>
						</ul>
					</div>
				</form>
				<h5><a href="index.html">返回主页</a></h5>
			</div>
      </div>
</div>
<!--inner block end here-->
<!--copy rights start here-->
<div class="copyrights">
	 <p>Copyright &copy; 2016.Company name All rights reserved.More Templates <a href="http://www.cssmoban.com/" target="_blank" title="模板之家">模板之家</a> - Collect from <a href="http://www.cssmoban.com/" title="网页模板" target="_blank">网页模板</a></p>
</div>
<!--COPY rights end here-->

<!--scrolling js-->
		<script src="js/jquery.nicescroll.js"></script>
		<script src="js/scripts.js"></script>
		<!--//scrolling js-->
<script src="js/bootstrap.js"> </script>
<!-- mother grid end here-->
</body>
</html>




